<?//添加分销商
use pft\Member\MemberAccount;

include('common/header.html');
include("common/left.html");
include('common/autoload.php');
// print_r($_SESSION);
// if($_SESSION['dtype']) {
    // exit('不合法的身份！');
// }
//进一步验证(防止有按钮没权限)员工身份
// echo ;
// $sql = "SELECT * FROM pft_member_extinfo WHERE fid=2";
// $sql="UPDATE pft_member_extinfo SET coop='' WHERE fid=2";
// $GLOBALS['le']->query($sql);
// while($row=$GLOBALS['le']->fetch_assoc()){
	// print_r($row);
// }

// exit;
if(isset($_SESSION['qx']) && $_SESSION['dtype']){
	if(!strpos('Placeholder'.$_SESSION['qx'],'addlow')){
		exit('不合法的身份！');
	}
}

// exit;
$mem = new MemberAccount($GLOBALS['le']);
//判断该供应商是否已添加admin为他的分销商
$ret = $mem->chkRelationship($_SESSION['memberID'], MemberAccount::ADMINID);

$csrf_token = genCsrfToken();
$data = array('csrf_token'=>$csrf_token,'web_title'=>$GLOBALS['web_title']);
if(!$ret['id']) {
    $data['admin'] = $mem->GetOne(MemberAccount::ADMINID);
//    print_r($data['admin']);
}

$GLOBALS['le']->query("SELECT add_saler_type FROM pft_member_extinfo WHERE fid={$_SESSION['memberID']}");
$GLOBALS['le']->fetch_assoc();
$ast = $GLOBALS['le']->f('add_saler_type');
//判断该供应商添加分销商的类型，只有管理员可以设置此项。合作比较深入的供应商可以使用搜索的方式添加分销商。否则都只能添加下级的分销商。
if($ast == 1) {
	
    $tplFile = 'tpl/distributor_add.tpl';
}
else {
    $tplFile = 'tpl/distributor_only_add_dt_a.html';
}

$tplEngine = new IdiotTplEngine($tplFile);
$tplEngine->SetData($data);
echo $tplEngine->Render();
include('common/footer.html');
?>